<template>
  <div>
    <el-drawer title="任务详情" :visible.sync="visible" :wrapperClosable="false" size='90%' append-to-body
      :loading="loading" :before-close="handleClose">
      <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="68px">
          <el-form-item label="项目名称" prop="projectId">
            <el-select v-model="queryParams.projectId" filterable placeholder="请选择项目名称" style="width: 240px">
              <el-option v-for="i in userListOptions" :key="i.projectId" :label="i.projectName" :value="i.projectId" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <!-- style="overflow-x: auto; display: flex;" -->
        <div>
          <div v-for="city in cityOptions" :key="city.id" class="cardAllSty">
            <div class="cardTextSty">{{ city.projectName }}
            </div>
            <div style="display: flex;flex-wrap: wrap;">
              <el-card shadow="always" class="cardListSty" v-for="item in city.subPlanList" :key="item.id">
                <div class="divDetail">

                  <span class="textSty" @click="handleDetail(item.id, item.status)">第{{
      item.cycleNo
    }}次维保任务，点击查看详情</span>
                </div>
                <div style="padding: 0 0 0.5rem 0.5rem">
                  <span class="textSty">{{ item.projectName }}</span>
                </div>
                <div style="display: flex; align-items: center; padding-bottom: 10px">
                  <div class="textIconSty">
                    <i class="el-icon-time"></i>
                    {{ item.planEndTime }} 截止
                  </div>
                  <el-button type="info" icon="el-icon-time" round size="mini" v-if="item.status == 1">{{ item.status |
      dynamicText(statusOptions) }}</el-button>
                  <el-button type="primary" icon="el-icon-check" round size="mini" v-if="item.status == 2">{{
      item.status |
      dynamicText(statusOptions) }}</el-button>
                  <el-button type="primary" icon="el-icon-check" round size="mini" v-if="item.status == 3">{{
      item.status |
      dynamicText(statusOptions) }}</el-button>
                  <el-button type="success" icon="el-icon-check" round size="mini" v-if="item.status == 4">{{
      item.status |
      dynamicText(statusOptions) }}</el-button>
                  <el-button type="danger" icon="el-icon-remove-outline" round size="mini" v-if="item.status == 5">{{
      item.status | dynamicText(statusOptions) }}</el-button>
                  <el-button type="success" icon="el-icon-check" round size="mini" v-if="item.status == 6">{{
      item.status |
      dynamicText(statusOptions) }}</el-button>
                </div>
              </el-card>
            </div>
          </div>
        </div>
        <Detail v-if="detailVisible" ref="Detail" @refreshDetail="refreshDetail" />
        <editFloorList v-if="editFloorVisible" ref="Detail" @refresh="editFloorVisible = false" />
        <taskDetail v-if="taskDetailVisible" ref="taskDetail"></taskDetail>
      </div>
    </el-drawer>
  </div>

</template>
<script>
import {
  getUserList,
  getProjectPlanByCustomerId,
  getProjectCountAndBuildingCountList,
  getListByCustomerId

} from "@/api/plan-produce/task";

import Detail from "./detail.vue";
import editFloorList from "./editFloor.vue";
import taskDetail from "./task-detail.vue";
export default {
  name: "Building",
  components: { Detail, editFloorList, taskDetail },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 委托单位列表
      userList: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 建筑表格数据
      buildingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      visible: false,
      // 详情页面
      detailVisible: false,
      // 编辑楼层
      editFloorVisible: false,
      taskDetailVisible: false,
      // 委托单位列表
      userListOptions: [],
      cityOptions: [],
      // 查询参数
      queryParams: {
        projectId: null,
      },
      customerId: null,
      statusOptions: [
        { fullName: "未预约", id: 1 },
        { fullName: "已预约", id: 2 },
        { fullName: "执行中", id: 3 },
        { fullName: "已完成", id: 4 },
        { fullName: "未完成", id: 5 },
        { fullName: "已完结", id: 6 },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        serviceOrgId: [
          {
            required: true,
            message: "消防技术服务机构id不能为空",
            trigger: "blur",
          },
        ],
        customerId: [
          { required: true, message: "委托单位不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {

  },

  methods: {
    init(id) {
      this.visible = true;
      this.customerId = id
      this.$nextTick(() => {
        this.getList();
      })
    },
    getList() {
      this.loading = true;
      // // 获取用户列表
      // getUserList("02").then((response) => {
      //   this.userListOptions = response.data;
      //   this.total = response.total;
      //   this.loading = false;
      // });
      getProjectPlanByCustomerId(this.customerId, this.queryParams).then(
        (res) => {
          this.cityOptions = res.data;
        }
      );
      getListByCustomerId(this.customerId).then(res => {
        this.userListOptions = res.data
      })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.customerId = '-1'
          this.cityOptions = []
          done();
        })
        .catch(_ => { });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serviceOrgId: null,
        customerId: null,
        name: null,
        address: null,
        pointPositionDesc: null,
        abovegroundNumber: null,
        undergroundNumber: null,
        longitude: null,
        latitude: null,
        invalid: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 跳转详情
    handleDetail(id, ids) {
      if (ids != 1) {
        this.detailVisible = true;
        this.$nextTick(() => {
          this.$refs.Detail.init(id);
        });
      } else {
        this.$modal.msgWarning('未预约无法查看详情');
      }
    },
    refreshDetail(list) {
      this.detailVisible = false;
      setTimeout(() => {
        this.taskDetailVisible = true;
        this.$nextTick(() => {
          this.$refs.taskDetail.init(list);
        });
      }, 0);
    },

  },
};
</script>
<style lang="scss" scoped rel="stylesheet/scss">
.mapSty {
  width: 100%;
  height: 450px;
  position: relative;
}

.cardAllSty {
  margin-top: 1rem;
  padding-left: 1rem;
  background: #f3f3f3;
  padding-bottom: 0.5rem;

}

.cardTextSty {
  margin-bottom: 0.5rem;
  padding-top: 0.5rem;
  color: rgb(68, 142, 247);

}

#allMap {
  width: 100%;
  height: 450px;
}

.divDetail {
  padding: 0.5rem 0 0.5rem 0.5rem;
  cursor: pointer;
  /* 设置鼠标样式为手型 */
}

.textSty {
  font-size: 14px;
  color: rgb(102, 102, 102);
}

.cardListSty {
  height: 6.5rem;
  width: 16.5rem;
  margin-bottom: 0.5rem;
  margin-right: 2rem;
}

.textIconSty {
  margin-left: 10px;
  font-size: 12px;
  color: rgb(102, 102, 102);
  margin-right: 0.3rem;
  // flex: 1;

  .listIcon {
    padding: 0 5px;
  }
}

.text-with-line {
  text-decoration: line-through;
}

::v-deep .el-card__body {
  padding: 0;
}
</style>
